package cn.daimajiangxin.springboot.learning.service;

import cn.daimajiangxin.springboot.learning.mapper.UserMapper;
import cn.daimajiangxin.springboot.learning.model.User;
import cn.daimajiangxin.springboot.learning.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {
    private final UserMapper userMapper;
    private final UserRepository userRepository;
    private final RedisTemplate<String, Object> redisTemplate;
    @Autowired
    public UserService(UserMapper userMapper, UserRepository userRepository, RedisTemplate<String, Object> redisTemplate) {
        this.userMapper = userMapper;
        this.userRepository=userRepository;
        this .redisTemplate=redisTemplate;
    }

    public List<User> getAllUsers() {
        return userMapper.findAllUsers();
    }

    public void add(User user) {
        userRepository.save(user);
        redisTemplate.boundValueOps("user_key").set(user);

    }

}


